package com.paradisecloudtech.vc.system.ui.fragment;

import android.support.design.widget.FloatingActionButton;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.common.library.Utils.LogUtil;
import com.common.library.Utils.ToastUtil;
import com.common.library.base.BaseFragment;
import com.paradisecloudtech.vc.system.R;
import com.paradisecloudtech.vc.system.adapter.ConfsAdapter;
import com.paradisecloudtech.vc.system.mvp.bean.ConfsBean;
import com.paradisecloudtech.vc.system.mvp.presenter.ConfsPresenter;
import com.paradisecloudtech.vc.system.mvp.view.ConfsView;

import butterknife.BindView;
import butterknife.OnClick;

public class ConfsFragment extends BaseFragment implements ConfsView {


    @BindView(R.id.rv_confs_list)
    RecyclerView rvConfsList;
    @BindView(R.id.fab_confs_add_btn)
    FloatingActionButton fabConfsAddBtn;

    public static ConfsFragment confsFragment;
    private ConfsPresenter confsPresenter;

    public ConfsFragment() {

    }

    public static ConfsFragment getInstance() {
        if (confsFragment == null) {
            confsFragment = new ConfsFragment();
        }
        return confsFragment;
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_conf;
    }

    @Override
    protected void initVar() {
        confsPresenter = new ConfsPresenter();
        LinearLayoutManager manager = new LinearLayoutManager(mContext);
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        rvConfsList.setLayoutManager(manager);
        rvConfsList.addItemDecoration(new DividerItemDecoration(mContext,DividerItemDecoration.VERTICAL));
    }

    @Override
    public void initData() {
        confsPresenter.attachView(this);
        confsPresenter.requestConfsData(1);
    }

    @Override
    public void initListener() {

    }


    @OnClick({R.id.fab_confs_add_btn})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.fab_confs_add_btn:
                break;
        }
    }

    @Override
    public void startGetConferences() {

    }

    @Override
    public void getConferencesSuccess(ConfsBean confsBean) {
        ConfsAdapter adapter = new ConfsAdapter(confsBean.getResult().getConferences(), mContext);
        rvConfsList.setAdapter(adapter);
    }

    @Override
    public void endGetConferences() {

    }

    @Override
    public void requestFailedByNet(Throwable throwable) {
        ToastUtil.showToast(throwable.getMessage());
    }

    @Override
    public void onDestroy() {
        confsPresenter.detachView();
        super.onDestroy();
    }
}
